var assert = require('assert');
let Validator = require('../index.js')
let name = "max校验"
let validator = new Validator()
let test=function(data,rules,messages,attributes,expect,message){
	let check = validator.check(data,rules,messages,attributes)
	describe(name, function() {
	  it('参数:'+JSON.stringify(data)+"|规则:"+JSON.stringify(rules), function() {
	      assert.equal(check.passes(), expect);
	      if(!expect){
	      	assert.equal(check.error(), message);
	      }
	  });
	});
}
let run = function(data){
	for(var i in data){
		test(data[i]["data"],data[i]["rules"],data[i]["messages"],data[i]["attributes"],data[i]["expect"],data[i]["message"])
	}
}
run([
	{
		data: {test: null},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: false,
		message: "test不能大于3个字符"
	},
	{
		data: {test: ''},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: true,
		message: null
	},
	{
		data: {},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: false,
		message: "test不能大于3个字符"
	},
	{
		data: {test:"12"},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: true,
		message: null
	},
	{
		data: {test:"12345"},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: false,
		message: "test不能大于3个字符"
	},
	{
		data: {test:5},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: false,
		message: "test不能大于3"
	},
	{
		data: {test:2},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: true,
		message: null
	},
	{
		data: {test:[1,2,3,4]},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: false,
		message: "test数组长度不能大于3"
	},
	{
		data: {test:[1,2]},
		rules: {test: "max:3"},
		messages: {},
		attributes: {},
		expect: true,
		message: null
	}
]);